package com.j2203.controller;

import com.j2203.entity.Game;
import com.j2203.entity.Img;
import com.j2203.service.gameService;
import com.j2203.vo.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/game")
public class gameController {
    @Autowired
    private gameService gameService;
    ResultMsg resMsg=new ResultMsg();
    @GetMapping("/type")
    //根据类型查询所有游戏
    public ResultMsg selectAll(int tid){
        List<Game> games = gameService.selectAll(tid);
        if (games!=null){
            resMsg.setStatus(200);
            resMsg.setData(games);
        }else {
            resMsg.setStatus(201);
        }
        return resMsg;
    }
    @GetMapping("/lunbo")
    //轮播图
    public List<Img> selectAllpic(int nid){
        List<Img> imgs = gameService.selectc(nid);
        System.out.println(imgs);
        return imgs;
    }
    @GetMapping("/suiji")
    //根据类型随机查询所有游戏
    public ResultMsg selectAll1(){
        List<Game> games = gameService.selectAll1();
        System.out.println(games);
        if (games!=null){
            resMsg.setStatus(200);
            resMsg.setData(games);
        }else {
            resMsg.setStatus(201);
        }
        return resMsg;
    }
    @GetMapping("/jiangxu")
    //根据价格降序查询所有游戏
    public ResultMsg selectAll2(){
        List<Game> games = gameService.selectAll2();
        if (games!=null){
            resMsg.setStatus(200);
            resMsg.setData(games);
        }else {
            resMsg.setStatus(201);
        }
        return resMsg;
    }
    @GetMapping("/mohu")
    //模糊查询游戏
    public ResultMsg selectMohu(String gname){
        List<Game> games = gameService.selectMohu(gname);
        if (games!=null){
            resMsg.setStatus(200);
            resMsg.setData(games);
        }else {
            resMsg.setStatus(201);
        }
        return resMsg;
    }
    @GetMapping("/all")
    //查询所有游戏
    public ResultMsg findAll(){
        System.out.println("/all");
        List<Game> games = gameService.fingAll();
        if (games!=null){
            resMsg.setStatus(200);
            resMsg.setData(games);
        }else {
            resMsg.setStatus(201);
        }
        return resMsg;
    }
}
